package com.tanhua.dashboard.service;



import com.alibaba.dubbo.config.annotation.Reference;


import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dashboard.controller.DashBoardController;
import com.tanhua.dashboard.enums.AgeRangeEnum;
import com.tanhua.dashboard.enums.RegionEnum;



import com.tanhua.dashboard.vo.DateVo;
import com.tanhua.dashboard.vo.DistributionVo;
import com.tanhua.dashboard.vo.InfoStatisticsVo;
import com.tanhua.dashboard.vo.UsersStatisticsVo;
import com.tanhua.dubbo.server.api.DashBoardApi;

import com.tanhua.user.enums.SexEnum;
import com.tanhua.user.mapper.UserInfoMapper;
import com.tanhua.user.mapper.UserMapper;

import com.tanhua.user.pojo.User;
import com.tanhua.user.pojo.UserInfo;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class DashBoardService2 {

    private static final Logger LOGGER = LoggerFactory.getLogger(DashBoardController.class);

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Reference(version = "1.0.0")
    private DashBoardApi dashBoardApi;


    /**
     * 统计
     *
     * @return
     */
    public InfoStatisticsVo InfoStatistics() {
        //创建VO对象
        InfoStatisticsVo infoStatisticsVo = new InfoStatisticsVo();
        Integer cumulativeUsersCount = null;
        Integer activePassMonthActiveCount = null;
        Integer activePassWeekActiveCount = null;
        Integer todayRegisterCount = null;
        Integer todayRate = null;
        Integer todayLoginCount = null;
        Integer todayLoginRate = null;
        Integer todayActiveCount = null;
        Integer yesterdayActiveCount = null;
        Integer todayActiveUsersRate = null;
        Integer yesterdayActiveUsersRate = null;

        try {
            //1. 查询累计用户(OK)
            cumulativeUsersCount = this.userMapper.selectCount(null);
            //2. 30天活跃用户(ok)//todo 修改表名
            activePassMonthActiveCount = this.dashBoardApi.queryActiveUser(-30,0);
            //3. 过去7天活跃用户(ok)
            activePassWeekActiveCount = this.dashBoardApi.queryActiveUser(-7,0);
            //4. 今日新增用户(ok)
            todayRegisterCount = this.newUserCount(0,1);
            //5. 今日新增用户环比增长率
            Integer yesterdayRegisterCount = this.newUserCount(-1,0);
            todayRate = this.getRate(todayRegisterCount,yesterdayRegisterCount);
            //6. 今日登录次数
            todayLoginCount = this.dashBoardApi.queryLoginCount(0);
            //7. 今日登录次数环比增长
            Integer yesterdayLoginCount = this.dashBoardApi.queryLoginCount(-1);
            todayLoginRate = this.getRate(todayLoginCount,yesterdayLoginCount);
            //8. 今日活跃用户数
            todayActiveCount = this.dashBoardApi.queryActiveUser(0,1);
            //11. 昨日活跃用户
            yesterdayActiveCount = this.dashBoardApi.queryActiveUser(-1,0);
            //9. 今日活跃用户环比增长
            todayActiveUsersRate = this.getRate(todayActiveCount,yesterdayActiveCount);
            //12. 昨日活跃用户环比增长
            Integer dubYesterdayActiveCount = this.dashBoardApi.queryActiveUser(-2,-1);
            yesterdayActiveUsersRate = this.getRate(todayActiveUsersRate,dubYesterdayActiveCount);
            //10. 过去7天平均使用时长


            Calendar calendarSd = Calendar.getInstance();
            Date time = calendarSd.getTime();
            String s = new DateTime(time).toString("yyyy-MM-dd : HH:mm:ss");
            long time1 = time.getTime();
            System.out.println(time1);
            System.out.println(s);


        } catch (Exception e) {
            e.printStackTrace();
        }


        //1. 查询累计用户(OK)
        infoStatisticsVo.setCumulativeUsers(cumulativeUsersCount);
        //2. 30天活跃用户(ok)
        infoStatisticsVo.setActivePassMonth(activePassMonthActiveCount);
        //3. 7天活跃用户(ok)
        infoStatisticsVo.setActivePassWeek(activePassWeekActiveCount);
        //4. 今日新增用户(ok)
        infoStatisticsVo.setNewUsersToday(todayRegisterCount);
        //5. 今日新增用户环比增长率
        infoStatisticsVo.setNewUsersTodayRate(todayRate);
        //6. 今日登录次数
        infoStatisticsVo.setLoginTimesToday(todayLoginCount);
        //7. 今日登录次数环比增长
        infoStatisticsVo.setLoginTimesTodayRate(todayLoginRate);
        //8. 今日活跃用户数
        infoStatisticsVo.setActiveUsersToday(todayActiveCount);
        //11. 昨日活跃用户
        infoStatisticsVo.setActiveUsersYesterday(yesterdayActiveCount);
        //9. 今日活跃用户环比增长
        infoStatisticsVo.setActiveUsersTodayRate(todayActiveUsersRate);
        //12. 昨日活跃用户环比增长
        infoStatisticsVo.setActiveUsersYesterdayRate(yesterdayActiveUsersRate);
        //10. 过去7天平均使用时长 todo
        infoStatisticsVo.setUseTimePassWeek(10);
        return infoStatisticsVo;
    }


    /**
     * 计算环比增长率
     * @param today
     * @param yesterday
     * @return
     */
    private int getRate(Integer today,Integer yesterday){
        int rete = 0;
        if (yesterday == 0) {
            if (today == 0) {
                rete = 0;
            } else {
                rete = 100;
            }
        } else {
            rete = (int) ((today - yesterday) / (yesterday * 1.0)) * 100;
        }
        return rete;
    }

    /**
     * 0,1 今日新增用户
     * -1,0 昨日新增用户
     * @return
     */
    private Integer newUserCount(int sd,int ed){
        QueryWrapper<User> newUserTodayQuery = new QueryWrapper<>();
        newUserTodayQuery.between("created", this.getDateTime(sd),this.getDateTime(ed));
        Integer count = this.userMapper.selectCount(newUserTodayQuery);
        return count;
    }

    /**
     * 0 今天的开始
     * -1 昨天的开始
     * -2 前天的开始
     * @param day
     * @return
     */
    private Date getDateTime(int day) {
        Calendar yesterdayEnd = Calendar.getInstance();
        yesterdayEnd.set(Calendar.HOUR_OF_DAY, 0);
        yesterdayEnd.set(Calendar.MINUTE, 0);
        yesterdayEnd.set(Calendar.SECOND, 0);
        yesterdayEnd.add(Calendar.DATE, day);
        return yesterdayEnd.getTime();
    }



    /*===========================================================*/
    /**
     * 统计面板
     * @param sd
     * @param ed
     * @param type
     * @return
     */
    public UsersStatisticsVo getUsers(Long sd, Long ed, Integer type) {
        //创建对象
        UsersStatisticsVo statisticsVo = new UsersStatisticsVo();
        switch (type){
            case 101://查询新增用户
                statisticsVo = this.getNewUsers(sd,ed);
                break;
            case 102://查询活跃用户
                statisticsVo = this.getActiveUsers(sd,ed);
                break;
            case 103:
                statisticsVo = this.getUserRate(sd,ed);
                break;
            default:
                break;
        }
        return statisticsVo;
    }

    /**
     * 查询新增用户
     * @param sd
     * @param ed
     * @return
     */
    private UsersStatisticsVo getNewUsers(Long sd, Long ed) {
        try {
            sd = new SimpleDateFormat("yyyy-MM-dd").parse(new SimpleDateFormat("yyyy-MM-dd").format(sd)).getTime();
            ed = new SimpleDateFormat("yyyy-MM-dd").parse(new SimpleDateFormat("yyyy-MM-dd").format(ed)).getTime();
        } catch (ParseException e) {
            LOGGER.error("日期转换异常！", e);
            e.printStackTrace();
        }
        //日期范围内的天数
        int sumDay = (int) ((ed - sd) / (24 * 60 * 60 * 1000)+1);
        List<DateVo> thisYear = new ArrayList<>();
        List<DateVo> lastYear = new ArrayList<>();
        for (int i = 0; i < sumDay; i++) {
            //thisYear
            //日期起点
            Calendar calendarSd = Calendar.getInstance();
            calendarSd.setTime(new Date(sd));
            Calendar cloneSd = (Calendar) calendarSd.clone();
            //日期终点
            Calendar calendarEd = Calendar.getInstance();
            calendarEd.setTime(new Date(ed));

            //lastYear
            Calendar calendarSdLast = Calendar.getInstance();
            calendarSdLast.setTime(new Date(sd));
            calendarSdLast.add(Calendar.YEAR,-1);
            Calendar cloneSdLast = (Calendar) calendarSd.clone();
            //日期终点
            Calendar calendarEdLast = Calendar.getInstance();
            calendarEdLast.setTime(new Date(ed));
            calendarEdLast.add(Calendar.YEAR,-1);

            //thisYear
            calendarSd.add(Calendar.DATE, i);
            Date beforeTime = calendarSd.getTime();

            cloneSd.add(Calendar.DATE, i + 1);
            Date afterTime = cloneSd.getTime();

            //lastYear
            calendarSdLast.add(Calendar.DATE, i);
            Date beforeTimeLast = calendarSd.getTime();

            cloneSdLast.add(Calendar.DATE, i + 1);
            Date afterTimeLast = calendarSd.getTime();



            //thisYear
            String dateTitle = new DateTime(beforeTime).toString("yyyy年MM月dd日");
            QueryWrapper<User> userQuery = new QueryWrapper<>();
            userQuery.between("created", beforeTime, afterTime);
            Integer userCount = this.userMapper.selectCount(userQuery);
            //lastYear
            String dateTitleLast = new DateTime(beforeTimeLast).toString("yyyy年MM月dd日");
            QueryWrapper<User> userQueryLast = new QueryWrapper<>();
            userQueryLast.between("created", beforeTimeLast, afterTimeLast);
            Integer userCountLast = this.userMapper.selectCount(userQueryLast);
            //封装数据
            thisYear.add(new DateVo(dateTitle,userCount));
            lastYear.add(new DateVo(dateTitleLast,userCountLast));
        }
        UsersStatisticsVo usersStatisticsVo = new UsersStatisticsVo();
        usersStatisticsVo.setThisYear(thisYear);
        usersStatisticsVo.setLastYear(lastYear);
        return usersStatisticsVo;
    }
    /**
     * 查询活跃用户
     * @param sd
     * @param ed
     * @return
     */
    private UsersStatisticsVo getActiveUsers(Long sd, Long ed) {
        try {
            sd = new SimpleDateFormat("yyyy-MM-dd").parse(new SimpleDateFormat("yyyy-MM-dd").format(sd)).getTime();
            ed = new SimpleDateFormat("yyyy-MM-dd").parse(new SimpleDateFormat("yyyy-MM-dd").format(ed)).getTime();
        } catch (ParseException e) {
            LOGGER.error("日期转换异常！", e);
            e.printStackTrace();
        }
        //日期范围内的天数
        int sumDay = (int) (((ed - sd) / (24 * 60 * 60 * 1000)) + 1);
        List<DateVo> thisYear = new ArrayList<>();
        List<DateVo> lastYear = new ArrayList<>();

        for (int i = 0; i < sumDay; i++) {
            //sdCalendar  1
            Calendar calendarSd = Calendar.getInstance();
            calendarSd.setTime(new Date(sd));
            //sdCalendar  2
            Calendar cloneSd = (Calendar) calendarSd.clone();

            //edCalendar
            Calendar calendarEd = Calendar.getInstance();
            calendarEd.setTime(new Date(ed));


            //thisYear
            calendarSd.add(Calendar.DATE, i);
            Date beforeTime = calendarSd.getTime();

            cloneSd.add(Calendar.DATE, i + 1);
            Date afterTime = cloneSd.getTime();

            //thisYearCount
            String dateTitle = new DateTime(beforeTime).toString("yyyy年MM月dd日");
            Integer userCount = this.dashBoardApi.queryActiveUser(beforeTime,afterTime);


            //去年
            //sdCalendar  1
            Calendar calendarSdLast = Calendar.getInstance();
            calendarSdLast.setTime(new Date(sd));
            calendarSdLast.add(Calendar.YEAR,-1);
            //sdCalendar  2
            Calendar cloneSdLast = (Calendar) calendarSd.clone();

            //edCalendar
            Calendar calendarEdLast = Calendar.getInstance();
            calendarEdLast.setTime(new Date(ed));
            calendarEdLast.add(Calendar.YEAR,-1);


            //lastYear
            calendarSdLast.add(Calendar.DATE, i);
            Date beforeTimeLast = calendarSd.getTime();

            cloneSdLast.add(Calendar.DATE, i + 1);
            Date afterTimeLast = calendarSd.getTime();

            //lastYear
            String dateTitleLast = new DateTime(beforeTimeLast).toString("yyyy年MM月dd日");
            Integer userCountLast = this.dashBoardApi.queryActiveUser(beforeTimeLast,afterTimeLast);


            //封装数据
            thisYear.add(new DateVo(dateTitle,userCount));
            lastYear.add(new DateVo(dateTitleLast,userCountLast));
        }
        UsersStatisticsVo usersStatisticsVo = new UsersStatisticsVo();
        usersStatisticsVo.setThisYear(thisYear);
        usersStatisticsVo.setLastYear(lastYear);
        return usersStatisticsVo;
    }
    /**
     * 查询次日留存率
     * @param sd
     * @param ed
     * @return
     */
    private UsersStatisticsVo getUserRate(Long sd, Long ed) {
        try {
            sd = new SimpleDateFormat("yyyy-MM-dd").parse(new SimpleDateFormat("yyyy-MM-dd").format(sd)).getTime();
            ed = new SimpleDateFormat("yyyy-MM-dd").parse(new SimpleDateFormat("yyyy-MM-dd").format(ed)).getTime();
        } catch (ParseException e) {
            LOGGER.error("日期转换异常！", e);
            e.printStackTrace();
        }
        //日期范围内的天数
        int sumDay = (int) (((ed - sd) / (24 * 60 * 60 * 1000)) + 1);
        List<DateVo> thisYear = new ArrayList<>();
        List<DateVo> lastYear = new ArrayList<>();

        for (int i = 0; i < sumDay; i++) {
            //thisYear
            //日期起点
            Calendar calendarSd = Calendar.getInstance();
            calendarSd.setTime(new Date(sd));
            Calendar cloneSd = (Calendar) calendarSd.clone();
            //日期终点
            Calendar calendarEd = Calendar.getInstance();
            calendarEd.setTime(new Date(ed));


            //lastYear
            Calendar calendarSdLast = Calendar.getInstance();
            calendarSdLast.setTime(new Date(sd));
            calendarSdLast.add(Calendar.YEAR,-1);
            Calendar cloneSdLast = (Calendar) calendarSdLast.clone();

            Calendar calendarEdLast = Calendar.getInstance();
            calendarEdLast.setTime(new Date(ed));
            calendarEdLast.add(Calendar.YEAR,-1);

            //thisYear
            calendarSd.add(Calendar.DATE, i);
            Date beforeTime = calendarSd.getTime();

            Calendar thisSdCloneBefore = (Calendar)calendarSd.clone();
            thisSdCloneBefore.add(Calendar.DATE,-1);
            Date beforeTimeClone = thisSdCloneBefore.getTime();

            cloneSd.add(Calendar.DATE, i + 1);
            Date afterTime = calendarSd.getTime();

            Calendar thisSdCloneAfter = (Calendar)cloneSd.clone();
            thisSdCloneAfter.add(Calendar.DATE,-1);
            Date afterTimeClone = thisSdCloneAfter.getTime();


            //lastYear
            calendarSdLast.add(Calendar.DATE, i);
            Date beforeTimeLast = calendarSd.getTime();

            Calendar lastSdCloneBefore = (Calendar)calendarSd.clone();
            lastSdCloneBefore.add(Calendar.DATE,-1);
            Date beforeTimeCloneLast = lastSdCloneBefore.getTime();

            cloneSdLast.add(Calendar.DATE, i + 1);
            Date afterTimeLast = calendarSd.getTime();

            Calendar lastSdCloneAfter = (Calendar)calendarSd.clone();
            lastSdCloneAfter.add(Calendar.DATE,-1);
            Date afterTimeCloneLast = lastSdCloneAfter.getTime();


            //thisYear
            String dateTitle = new DateTime(beforeTime).toString("yyyy年MM月dd日");
            //查询昨天所有创建用户
            LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
            wrapper.between(User::getCreated, beforeTimeClone, afterTimeClone);
            List<User> userInfoList = userMapper.selectList(wrapper);
            List<Long> userIds = userInfoList.stream().map(User::getId).collect(Collectors.toList());
            List<Integer> userIdsInt = JSONArray.parseArray(userIds.toString(),Integer.class);

            //lastYear
            String dateTitleLast = new DateTime(beforeTimeLast).toString("yyyy年MM月dd日");
            //一年前
            LambdaQueryWrapper<User> wrapperLast = new LambdaQueryWrapper<>();
            wrapperLast.between(User::getCreated,beforeTimeCloneLast, afterTimeCloneLast);
            List<User> userInfoListLast = userMapper.selectList(wrapperLast);
            List<Long> userIdsLast = userInfoListLast.stream().map(User::getId).collect(Collectors.toList());
            List<Integer> userIdsLastInt = JSONArray.parseArray(userIdsLast.toString(),Integer.class);


            Integer ActiveCount = this.dashBoardApi.queryActiveUser(userIdsInt,beforeTime.getTime(), afterTime.getTime());
            Integer ActiveCountLast = this.dashBoardApi.queryActiveUser(userIdsLastInt,beforeTimeLast.getTime(), afterTimeLast.getTime());

            int thisRate = 0;
            if (userIds.size() > 0){
                thisRate = (int)((userIds.size() - ActiveCount)/(userIds.size()*1.0) * 100);
            }
            int lastRate = 0;
            if (userIds.size() > 0){
                lastRate = (int)((userIdsLast.size() - ActiveCountLast)/(userIdsLast.size()*1.0) * 100);
            }

            //封装数据
            thisYear.add(new DateVo(dateTitle,thisRate));
            lastYear.add(new DateVo(dateTitleLast,lastRate));
        }
        UsersStatisticsVo usersStatisticsVo = new UsersStatisticsVo();
        usersStatisticsVo.setThisYear(thisYear);
        usersStatisticsVo.setLastYear(lastYear);
        return usersStatisticsVo;
    }
    /*==============================================================================*/
    /**
     * 分布
     *
     * @param sd
     * @param ed
     * @return
     */
    public DistributionVo getDistribution(Long sd, Long ed) {

        DistributionVo distributionVo = new DistributionVo();//创建对象
        List<DateVo> industryDistribution = new ArrayList<>();//行业分布top10
        List<DateVo> ageDistribution = new ArrayList<>();//年龄分布
        List<DateVo> genderDistribution = new ArrayList<>();//性别分布
        List<DateVo> localDistribution = new ArrayList<>();//地区分布
        List<DateVo> localTotal = new ArrayList<>();//地区合计


        try {
            sd = new SimpleDateFormat("yyyy-MM-dd").parse(new SimpleDateFormat("yyyy-MM-dd").format(sd)).getTime();
            ed = new SimpleDateFormat("yyyy-MM-dd").parse(new SimpleDateFormat("yyyy-MM-dd").format(ed)).getTime();
        } catch (ParseException e) {
            LOGGER.error("日期转换异常！", e);
            e.printStackTrace();
        }

        //今年起始，结束日期
        Calendar thisYearSD = Calendar.getInstance();
        thisYearSD.setTime(new Date(sd));

        Calendar thisYearED = Calendar.getInstance();
        thisYearED.setTime(new Date(ed));
        thisYearED.add(Calendar.DATE,1);


        //获取查询区间
        Date sdTime = thisYearSD.getTime();
        Date edTime = thisYearED.getTime();

        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("created", sdTime, edTime);
        List<UserInfo> userInfos = this.userInfoMapper.selectList(queryWrapper);



        //1. 性别
        int manCount = 0;
        int womanCount = 0;
        Map<String, Integer> industry = new HashMap<>();
        Integer number = 1;

        //2. 年龄
        int agelt20 = 0;
        int agegte20lt30 = 0;
        int agegte30lt40 =0;
        int agegte40lte50 = 0;
        int agegt50 = 0;


        //3. 地区分布计数
        Integer region1Amount = 0;
        Integer region2Amount = 0;
        Integer region3Amount = 0;
        Integer region4Amount = 0;
        Integer region5Amount = 0;
        Integer region6Amount = 0;
        Integer region7Amount = 0;
        Integer region8Amount = 0;
        Integer region9Amount = 0;
        Integer region10Amount = 0;
        Integer region11Amount = 0;
        Integer region12Amount = 0;
        Integer region13Amount = 0;
        Integer region14Amount = 0;
        Integer region15Amount = 0;
        Integer region16Amount = 0;
        Integer region17Amount = 0;
        Integer region18Amount = 0;
        Integer region19Amount = 0;
        Integer region20Amount = 0;
        Integer region21Amount = 0;
        Integer region22Amount = 0;
        Integer region23Amount = 0;
        Integer region24Amount = 0;
        Integer region25Amount = 0;
        Integer region26Amount = 0;
        Integer region27Amount = 0;
        Integer region28Amount = 0;
        Integer region29Amount = 0;
        Integer region30Amount = 0;
        Integer region31Amount = 0;
        Integer region32Amount = 0;
        Integer region33Amount = 0;
        Integer region34Amount = 0;


        for (UserInfo userInfo : userInfos) {

            String city = userInfo.getCity();
            SexEnum sex = userInfo.getSex();
            Integer age = userInfo.getAge();


            //1. 性别
            if (sex.getValue() == 1) {
                manCount++;
            } else if (sex.getValue() == 2) {
                womanCount++;
            }

            //行业
            if (industry.get(userInfo.getIndustry()) == null) {
                industry.put(userInfo.getIndustry(), number);
            } else {
                Integer industryCount = industry.get(userInfo.getIndustry());
                industry.put(userInfo.getIndustry(), ++industryCount);
            }

            //2. 年龄
            if (age < 20){
                agelt20++;
            } else if (age >= 20 && age <30){
                agegte20lt30++;
            } else if (age >=30 && age < 40){
                agegte30lt40++;
            } else if (age >= 40 && age <= 50){
                agegte40lte50++;
            } else if (age > 50){
                agegt50++;
            }

            //3. 地区
            if (StringUtils.contains(city, RegionEnum.REGION_ENUM_1.toString())) {
                region1Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_2.toString())) {
                region2Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_3.toString())) {
                region3Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_4.toString())) {
                region4Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_5.toString())) {
                region5Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_6.toString())) {
                region6Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_7.toString())) {
                region7Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_8.toString())) {
                region8Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_9.toString())) {
                region9Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_10.toString())) {
                region10Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_11.toString())) {
                region11Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_12.toString())) {
                region12Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_13.toString())) {
                region13Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_14.toString())) {
                region14Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_15.toString())) {
                region15Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_16.toString())) {
                region16Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_17.toString())) {
                region17Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_18.toString())) {
                region18Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_19.toString())) {
                region19Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_20.toString())) {
                region20Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_21.toString())) {
                region21Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_22.toString())) {
                region22Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_23.toString())) {
                region23Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_24.toString())) {
                region24Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_25.toString())) {
                region25Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_26.toString())) {
                region26Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_27.toString())) {
                region27Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_28.toString())) {
                region28Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_29.toString())) {
                region29Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_30.toString())) {
                region30Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_31.toString())) {
                region31Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_32.toString())) {
                region32Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_33.toString())) {
                region33Amount++;
            } else if (StringUtils.contains(city, RegionEnum.REGION_ENUM_34.toString())) {
                region34Amount++;
            }
        }




        //1. 性别
        genderDistribution.add(new DateVo("男性用户",manCount));
        genderDistribution.add(new DateVo("女性用户",womanCount));

        //2. 行业分布
        industry.forEach(
                (String key, Integer value) -> {
                    DateVo dateVo = new DateVo();
                    dateVo.setTitle(key);
                    dateVo.setAmount(value);
                    industryDistribution.add(dateVo);
                }
        );

        //3. 年龄分布
        ageDistribution.add(new DateVo(AgeRangeEnum.UNDER_TWENTY.getDesc(),agelt20));
        ageDistribution.add(new DateVo(AgeRangeEnum.TWENTY.getDesc(),agegte20lt30));
        ageDistribution.add(new DateVo(AgeRangeEnum.THIRTY.getDesc(),agegte30lt40));
        ageDistribution.add(new DateVo(AgeRangeEnum.FORTY.getDesc(),agegte40lte50));
        ageDistribution.add(new DateVo(AgeRangeEnum.OVER_FIFTY.getDesc(),agegt50));
        distributionVo.setAgeDistribution(ageDistribution);


        //4. 地区分布
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_1.toString(), region1Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_2.toString(), region2Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_3.toString(), region3Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_4.toString(), region4Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_5.toString(), region5Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_6.toString(), region6Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_7.toString(), region7Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_8.toString(), region8Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_9.toString(), region9Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_10.toString(), region10Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_11.toString(), region11Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_12.toString(), region12Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_13.toString(), region13Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_14.toString(), region14Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_15.toString(), region15Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_16.toString(), region16Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_17.toString(), region17Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_18.toString(), region18Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_19.toString(), region19Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_20.toString(), region20Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_21.toString(), region21Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_22.toString(), region22Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_23.toString(), region23Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_24.toString(), region24Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_25.toString(), region25Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_26.toString(), region26Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_27.toString(), region27Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_28.toString(), region28Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_29.toString(), region29Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_30.toString(), region30Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_31.toString(), region31Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_32.toString(), region32Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_33.toString(), region33Amount));
        localDistribution.add(new DateVo(RegionEnum.REGION_ENUM_34.toString(), region34Amount));

        //5. 地区综合
        localTotal.add(new DateVo(RegionEnum.REGION_ENUM_1.getValue(), region1Amount + region2Amount + region3Amount));
        localTotal.add(new DateVo(RegionEnum.REGION_ENUM_4.getValue(), region4Amount + region5Amount + region6Amount + region7Amount + region8Amount + region9Amount + region10Amount + region11Amount));
        localTotal.add(new DateVo(RegionEnum.REGION_ENUM_12.getValue(), region12Amount + region13Amount + region14Amount + region15Amount + region16Amount));
        localTotal.add(new DateVo(RegionEnum.REGION_ENUM_17.getValue(), region17Amount + region18Amount + region19Amount));
        localTotal.add(new DateVo(RegionEnum.REGION_ENUM_20.getValue(), region20Amount + region21Amount + region22Amount + region23Amount + region24Amount));
        localTotal.add(new DateVo(RegionEnum.REGION_ENUM_25.getValue(), region25Amount + region26Amount + region27Amount + region28Amount + region29Amount));
        localTotal.add(new DateVo(RegionEnum.REGION_ENUM_30.getValue(), region30Amount + region31Amount + region32Amount + region33Amount + region34Amount));

        //1. 性别
        distributionVo.setGenderDistribution(genderDistribution);
        //2. 行业分布
        distributionVo.setIndustryDistribution(industryDistribution);
        //3. 年龄分布
        distributionVo.setAgeDistribution(ageDistribution);
        //4. 地区分布
        distributionVo.setLocalDistribution(localDistribution);
        //5. 地区综合
        distributionVo.setLocalTotal(localTotal);

        return distributionVo;
    }
}
